package com.gao.mq.handler.impl;

import com.gao.mq.dto.EmailContentModel;
import com.gao.mq.handler.IMessageHandler;
import com.gao.mq.handler.MessageHandlerBase;
import com.gao.mq.domain.MessageInfo;
import com.gao.mq.util.EmailUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 邮件处理实现类
 */
@Component
public class EmailHandler extends MessageHandlerBase implements IMessageHandler {

    private static final Logger logger = LoggerFactory.getLogger(SmsHandler.class);

    @Autowired
    private EmailUtil emailUtil;

    @Override
    public boolean handler(MessageInfo messageInfo) {
        EmailContentModel emailContentModel = (EmailContentModel) messageInfo.getContentModel();
        try {
            emailUtil.send(messageInfo.getReceiver(), emailContentModel.getTitle(),
                    emailContentModel.getContent(), true, null);
            logger.info("邮件发送成功");
        } catch (Exception e) {
            e.printStackTrace();
            logger.error("邮件发送失败:{}", e.getMessage());
            return false;
        }
        return false;
    }
}
